

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/my-blog/img/fluid.png">
  <link rel="icon" href="/my-blog/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="木舟">
  <meta name="keywords" content="python Vue Test 测试开发 自动化测试">
  
    <meta name="description" content="前言指令是带有 v- 前缀的特殊 attribute。Vue 提供了许多内置指令，包括上面我们所介绍的 v-bind 和 v-html。 指令 attribute 的期望值为一个 JavaScript 表达式 (除了少数几个例外，即之后要讨论到的 v-for、v-on 和 v-slot)。 一个指令的任务是在其表达式的值变化时响应式地更新 DOM。以 v-if 为例： 1&lt;p v-if&#x3D;&amp;q">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue指令">
<meta property="og:url" content="https://walker_kwu.gitee.io/my-blog/2022/11/07/notes/vue/directives/">
<meta property="og:site_name" content="My Blog">
<meta property="og:description" content="前言指令是带有 v- 前缀的特殊 attribute。Vue 提供了许多内置指令，包括上面我们所介绍的 v-bind 和 v-html。 指令 attribute 的期望值为一个 JavaScript 表达式 (除了少数几个例外，即之后要讨论到的 v-for、v-on 和 v-slot)。 一个指令的任务是在其表达式的值变化时响应式地更新 DOM。以 v-if 为例： 1&lt;p v-if&#x3D;&amp;q">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-11-07T02:15:15.000Z">
<meta property="article:modified_time" content="2023-05-23T10:37:53.260Z">
<meta property="article:author" content="木舟">
<meta property="article:tag" content="测试开发">
<meta property="article:tag" content="测试平台">
<meta property="article:tag" content="javascript">
<meta property="article:tag" content="Vue">
<meta name="twitter:card" content="summary_large_image">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>Vue指令 - My Blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/my-blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/my-blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/my-blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"walker_kwu.gitee.io","root":"/my-blog/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/my-blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/my-blog/js/utils.js" ></script>
  <script  src="/my-blog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/my-blog/">
      <strong>木舟</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/my-blog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Vue指令"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        木舟
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-11-07 10:15" pubdate>
          2022年11月7日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          8.3k 字
        
      </span>
    

    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Vue指令</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：2023年5月23日 晚上
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>指令是带有 v- 前缀的特殊 attribute。Vue 提供了许多内置指令，包括上面我们所介绍的 v-bind 和 v-html。</p>
<p>指令 attribute 的期望值为一个 JavaScript 表达式 (除了少数几个例外，即之后要讨论到的 v-for、v-on 和 v-slot)。</p>
<p>一个指令的任务是在其表达式的值变化时响应式地更新 DOM。以 v-if 为例：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs template">&lt;p v-if=&quot;seen&quot;&gt;Now you see me&lt;/p&gt;<br></code></pre></td></tr></table></figure>
<p>这里，v-if 指令会基于表达式 seen 的值的true/false来移除/插入该 <code>&lt;p&gt;</code> 元素。</p>
<p>下面会介绍Vue在实际开发中都会用到的内置指令，务必要掌握。</p>
<h1 id="v-text"><a href="#v-text" class="headerlink" title="v-text"></a>v-text</h1><p>更新元素的文本内容，参数必须为组件定义的属性。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs template">&lt;span v-text=&quot;msg&quot;&gt;&lt;/span&gt;<br>&lt;!-- 等同于 --&gt;<br>&lt;span&gt;&#123;&#123;msg&#125;&#125;&lt;/span&gt;<br></code></pre></td></tr></table></figure>

<p><strong>模板表达式(使用 JavaScript 表达式)</strong></p>
<p>在模板中，调用vue组件属性，可以在属性的基础上，调用函数或编写javascript表达式</p>
<p>但并不代表所有函数都可以调用，要求必须是 <strong>有返回值</strong>，比如：console.log(xx) 就不可以被调用</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs template">&lt;div&gt;&#123;&#123; flag == 0 ? &#x27;我是muzhou0&#x27; : &#x27;我是muzhou1&#x27; &#125;&#125;&lt;/div&gt;<br>&lt;div&gt;&#123;&#123; num + 1 &#125;&#125;&lt;/div&gt;<br>&lt;div&gt;&#123;&#123; message.split(&#x27;,&#x27;) &#125;&#125;&lt;/div&gt;<br>&lt;div :id=&quot;`list-$&#123;id&#125;`&quot;&gt;&lt;/div&gt;<br></code></pre></td></tr></table></figure>


<h1 id="v-bind"><a href="#v-bind" class="headerlink" title="v-bind"></a>v-bind</h1><p>该指令用于在html元素上 <strong>添加响应式属性</strong></p>
<p>只要是通过 <code>v-bind</code> 声明的属性，都是一个正常的 <strong>html属性</strong> ，与组件中通过 <strong>响应式声明</strong> 的属性挂钩后，即为 <strong>响应式属性</strong>。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;script setup&gt;<br>  import &#123;ref&#125; from &#x27;vue&#x27;<br>  const url = ref(&quot;https://www.baidu.com&quot;)<br><br>  const changeUrl = ()=&gt;&#123;<br>    url.value = &quot;https://www.sina.com&quot;<br>  &#125;<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;a :href=&quot;url&quot;&gt;点我跳转&lt;/a&gt;<br>  &lt;button @click=&quot;changeUrl&quot;&gt;改变链接&lt;/button&gt;<br>&lt;/template&gt;<br></code></pre></td></tr></table></figure>

<p><code>v-bind</code> 可以简写为 <code>:</code></p>
<p>上述 <code>:href</code> 实际上等于 <code>v-bind:href</code></p>
<p>项目中，几乎都是直接通过 冒号 来声明 v-bind 。</p>
<h2 id="特殊写法"><a href="#特殊写法" class="headerlink" title="特殊写法"></a>特殊写法</h2><p>由于 v-bind 指定响应式属性的写法，如果要区分 <strong>非字符串属性、非响应式属性</strong> 时，比如：数字、布尔</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs template">&lt;div<br>:num=&quot;1&quot;<br>:bool=&quot;true&quot;<br>str=&quot;str&quot;<br>:data=&quot;vueData&quot;<br>&gt;&lt;/div&gt;<br></code></pre></td></tr></table></figure>


<h2 id="动态绑定多个属性值"><a href="#动态绑定多个属性值" class="headerlink" title="动态绑定多个属性值"></a>动态绑定多个属性值</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div v-bind=&quot;attributes&quot;&gt;&lt;/div&gt;<br>  &lt;button @click=changeAttribute&gt;改变属性值&lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>import &#123; ref &#125; from &#x27;vue&#x27;;<br><br>  const attributes = ref(&#123;<br>    id: &quot;muzhouId&quot;,<br>    class: &quot;muzhouClass&quot;<br>  &#125;)<br><br>  const changeAttribute = ()=&gt;&#123;<br>    attributes.value.id = &quot;muzhouIdChange&quot;<br>  &#125;<br><br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<h2 id="class与style"><a href="#class与style" class="headerlink" title="class与style"></a>class与style</h2><p>class和style，通过 v-bind 的绑定比较特殊，需要单独介绍。</p>
<h3 id="class"><a href="#class" class="headerlink" title="class"></a>class</h3><h4 id="原生和响应式并存"><a href="#原生和响应式并存" class="headerlink" title="原生和响应式并存"></a>原生和响应式并存</h4><p>Vue组件元素支持使用原生的class，也支持 响应式class</p>
<p>但由于class属性可以存在多个，所以当使用原生+响应式时，Vue也做支持</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div<br>  class=&quot;class1&quot;<br>  :class=&quot;class2&quot;<br>  &gt;&lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>  import &#123;ref&#125; from &#x27;vue&#x27;<br>  const class2 = ref(&quot;class2&quot;)<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<p>此时渲染出来的div就会有 class1、class2</p>
<h4 id="绑定对象"><a href="#绑定对象" class="headerlink" title="绑定对象"></a>绑定对象</h4><p>下面面的语法表示 active 是否存在取决于数据属性 isActive 的true/false。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs template">&lt;div :class=&quot;&#123; active: isActive &#125;&quot;&gt;&lt;/div&gt;<br></code></pre></td></tr></table></figure>

<p>同样原生+响应式可以并存：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>&lt;div<br>  class=&quot;static&quot;<br>  :class=&quot;&#123; active: isActive, &#x27;text-danger&#x27;: hasError &#125;&quot;<br>&gt;&lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;!-- <br>const isActive = ref(true)<br>const hasError = ref(false)<br> --&gt;<br></code></pre></td></tr></table></figure>

<h4 id="绑定数组"><a href="#绑定数组" class="headerlink" title="绑定数组"></a>绑定数组</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>&lt;div :class=&quot;[activeClass, errorClass]&quot;&gt;&lt;/div&gt;<br>&lt;/template&gt;<br>&lt;!-- <br>const activeClass = ref(&#x27;active&#x27;)<br>const errorClass = ref(&#x27;text-danger&#x27;)<br> --&gt;<br></code></pre></td></tr></table></figure>

<h3 id="style"><a href="#style" class="headerlink" title="style"></a>style</h3><h4 id="绑定对象-1"><a href="#绑定对象-1" class="headerlink" title="绑定对象"></a>绑定对象</h4><p>:style 支持绑定 JavaScript 对象值，对应的是 HTML 元素的 style 属性：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>&lt;div :style=&quot;&#123; color: activeColor, fontSize: fontSize + &#x27;px&#x27; &#125;&quot;&gt;&lt;/div&gt;<br>&lt;div :style=&quot;&#123; &#x27;font-size&#x27;: fontSize + &#x27;px&#x27; &#125;&quot;&gt;&lt;/div&gt;<br>&lt;div :style=&quot;&#123; &#x27;font-size&#x27;: &#x27;30px&#x27; &#125;&quot;&gt;&lt;/div&gt;<br>&lt;/template&gt;<br>&lt;!-- <br>const activeColor = ref(&#x27;red&#x27;)<br>const fontSize = ref(30)<br> --&gt;<br></code></pre></td></tr></table></figure>

<p>如果css属性中，需要有 <code>-</code> 隔开，比如上述的 <code>font-size</code> 或者 <code>background-color</code></p>
<p>都可以通过 <strong>驼峰写法</strong> 来表示, <code>fontSize</code> <code>backgroundColor</code></p>
<h4 id="绑定数组-1"><a href="#绑定数组-1" class="headerlink" title="绑定数组"></a>绑定数组</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>&lt;div :style=&quot;[baseStyles, overridingStyles]&quot;&gt;&lt;/div&gt;<br>&lt;/template&gt;<br></code></pre></td></tr></table></figure>


<h1 id="v-show"><a href="#v-show" class="headerlink" title="v-show"></a>v-show</h1><p>基于表达式值的true/false，来改变元素的可见性。</p>
<p>当条件改变时，会触发<strong>过渡效果</strong>。</p>
<p>与 <code>v-if</code> 不同的是，如果表达式为 false 时，元素不显示，但Dom中仍存在。</p>
<p>因为 v-show 是通过 修改display属性值来控制元素的显示的。</p>
<p>如果表达式为 true，则保持原有的display属性值</p>
<p>如果表达式为false，display就为none</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs template">&lt;!-- display: none --&gt;<br>&lt;div<br>v-show=&quot;false&quot;<br>&gt;&lt;/div&gt;<br></code></pre></td></tr></table></figure>

<h1 id="v-if"><a href="#v-if" class="headerlink" title="v-if"></a>v-if</h1><p>基于表达式值的true/false，来条件性地渲染元素或者模板片段。</p>
<p>当 v-if 元素被触发，元素及其所包含的指令/组件都会销毁和重构。如果初始条件是false，那么其内部的内容根本都不会被渲染。</p>
<p>当条件改变时会触发 <strong>过渡效果</strong>。</p>
<p>当同时使用时，v-if 比 v-for 优先级更高。不推荐在一元素上同时使用这两个指令。</p>
<p>当然，v-if支持多分支判断：<code>v-else-if/v-else</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div<br>  v-if=&quot;vif&quot;<br>  &gt;v-if&lt;/div&gt;<br><br>  &lt;div<br>  v-if=&quot;!vif&quot;<br>  &gt;&lt;/div&gt;<br>  &lt;div<br>  v-else-if=&quot;velseif&quot;<br>  &gt;v-else-if&lt;/div&gt;<br><br>  &lt;div<br>  v-if=&quot;!vif&quot;<br>  &gt;&lt;/div&gt;<br>  &lt;div<br>  v-else-if=&quot;!velseif&quot;<br>  &gt;&lt;/div&gt;<br>  &lt;div<br>  v-else<br>  &gt;v-else&lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>import &#123; ref &#125; from &#x27;vue&#x27;;<br><br>  const vif = ref(true)<br><br>  const velseif = ref(true)<br><br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<h1 id="v-on"><a href="#v-on" class="headerlink" title="v-on"></a>v-on</h1><p>给元素绑定事件监听。</p>
<p>相当于：<code>&lt;div onclick=&quot;click&quot;&gt;&lt;/div&gt;</code>/<code>el.addEventListener(&#39;click&#39;, function()&#123;&#125;)</code></p>
<p>参数可以有：</p>
<ul>
<li>组件方法</li>
<li>箭头函数</li>
<li>一行代码</li>
<li>对象</li>
</ul>
<p><code>v-on</code> 可以简写为 <code>@</code></p>
<h2 id="组件方法"><a href="#组件方法" class="headerlink" title="组件方法"></a>组件方法</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;button @click=&quot;onClick&quot;&gt;点我哦&lt;/button&gt;<br>  &lt;button v-on:click=&quot;onClick&quot;&gt;点我哦&lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>  const onClick = (e)=&gt;&#123;<br>    console.log(e);<br>  &#125;<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<h2 id="箭头函数"><a href="#箭头函数" class="headerlink" title="箭头函数"></a>箭头函数</h2><p>箭头函数中，只能使用组件中定义的属性和方法</p>
<p>比如，你在其中使用 <code>console.log()</code> 会报错</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &#123;&#123;value&#125;&#125;<br>  &lt;button @click=&quot;()=&gt;&#123;value = 2&#125;&quot;&gt;点我哦&lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>  import &#123;ref&#125; from &#x27;vue&#x27;<br>  const value = ref(1)<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<h2 id="一行代码"><a href="#一行代码" class="headerlink" title="一行代码"></a>一行代码</h2><p>一行代码一般用来快速改变组件属性的值</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &#123;&#123;disabled&#125;&#125;<br>  &lt;button @click=&quot;disabled=!disabled&quot;&gt;点我哦&lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>  import &#123;ref&#125; from &#x27;vue&#x27;<br>  const disabled = ref(true)<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<h2 id="对象"><a href="#对象" class="headerlink" title="对象"></a>对象</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;button v-on=&quot;&#123;click: onClick, change: onChange&#125;&quot;&gt;点我哦&lt;/button&gt;<br>&lt;/template&gt;<br></code></pre></td></tr></table></figure>

<h2 id="动态事件"><a href="#动态事件" class="headerlink" title="动态事件"></a>动态事件</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;button v-on:[event]=&quot;doThis&quot;&gt;&lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>    import &#123;ref&#125; from &#x27;vue&#x27;<br>    const event = ref(&quot;click&quot;)<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>


<h2 id="默认参数-event"><a href="#默认参数-event" class="headerlink" title="默认参数 $event"></a>默认参数 $event</h2><p><code>$event</code> 为默认参数，你可以显式传入</p>
<h3 id="隐式传入"><a href="#隐式传入" class="headerlink" title="隐式传入"></a>隐式传入</h3><p>当调用的方法不是通过 <strong>emit</strong> 回传的方法，且没有参数时，<code>$event</code>会当作默认参数传入</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;button @click=&quot;onClick&quot;&gt;点我哦&lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>  // e就是 $event<br>  const onClick = (e)=&gt;&#123;<br>    console.log(e);<br>  &#125;<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<h3 id="显式传入"><a href="#显式传入" class="headerlink" title="显式传入"></a>显式传入</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;button @click=&quot;onClick(1, $event)&quot;&gt;点我哦&lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>  // e就是 $event<br>  const onClick = (value, e)=&gt;&#123;<br>    console.log(e);<br>  &#125;<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<h2 id="可支持的事件"><a href="#可支持的事件" class="headerlink" title="可支持的事件"></a>可支持的事件</h2><p>只要是html支持的事件，vue都支持，不过使用时，需要把开头的 <code>on</code> 转写成 <code>@</code></p>
<p>比如：<code>onmouseover</code> -&gt; <code>@mouseover</code></p>
<h2 id="事件修饰符"><a href="#事件修饰符" class="headerlink" title="事件修饰符"></a>事件修饰符</h2><ul>
<li>.stop ——调用 event.stopPropagation()。阻止父元素的事件，@click.stop</li>
<li>.prevent ——调用 event.preventDefault()。</li>
<li>.capture ——在捕获模式添加事件监听器。会改变 <strong>事件冒泡</strong> 顺序</li>
<li>.self ——只有事件从元素本身发出才触发处理函数。阻止子元素的事件</li>
<li>.{keyAlias} ——只在某些按键下触发处理函数。比如@keyup.enter</li>
<li>.once ——最多触发一次处理函数。</li>
<li>.left ——只在鼠标左键事件触发处理函数。</li>
<li>.right ——只在鼠标右键事件触发处理函数。</li>
<li>.middle ——只在鼠标中键事件触发处理函数。</li>
<li>.passive ——通过 { passive: true } 附加一个 DOM 事件。提前告知html，我不会阻止你html的默认事件，提高性能</li>
</ul>
<h1 id="v-for"><a href="#v-for" class="headerlink" title="v-for"></a>v-for</h1><p>基于原始数据多次渲染元素或模板块。</p>
<p>不推荐与 <code>v-if</code> 一起使用。</p>
<p>期望的循环类型：</p>
<ul>
<li>数组</li>
<li>对象</li>
<li>数字</li>
<li>字符串</li>
<li>迭代器（Map、Set）</li>
</ul>
<p>使用时，不能直接使用其具体的值，而是使用值对应的变量。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div v-for=&quot;item in items&quot; :key=&quot;item.id&quot;&gt;&#123;&#123;item.text&#125;&#125;&lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>  import &#123;ref&#125; from &#x27;vue&#x27;<br><br>  const items = ref([<br>    &#123;id: 1, text: &#x27;text1&#x27;&#125;,<br>    &#123;id: 2, text: &#x27;text2&#x27;&#125;,<br>    &#123;id: 3, text: &#x27;text3&#x27;&#125;,<br>  ])<br><br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<h2 id="获取索引"><a href="#获取索引" class="headerlink" title="获取索引"></a>获取索引</h2><p><code>&lt;div v-for=&quot;(item, index) in items&quot;&gt;&lt;/div&gt;</code></p>
<h2 id="获取key"><a href="#获取key" class="headerlink" title="获取key"></a>获取key</h2><p><code>&lt;div v-for=&quot;(value, key) in object&quot;&gt;&lt;/div&gt;</code></p>
<h2 id="获取索引和key"><a href="#获取索引和key" class="headerlink" title="获取索引和key"></a>获取索引和key</h2><p><code>&lt;div v-for=&quot;(value, name, index) in object&quot;&gt;&lt;/div&gt;</code></p>
<h2 id="尽量指定唯一的key"><a href="#尽量指定唯一的key" class="headerlink" title="尽量指定唯一的key"></a>尽量指定唯一的key</h2><p>使用v-for时，尽量去指定一个具有 <strong>唯一性的key</strong></p>
<p>Vue的组件更新原理，实际上是进行key的比较，key发生变动，将重新渲染加载。</p>
<p>如果属性值变动后，key值在前后对比下没有变动，对应的元素将不会更新。</p>
<p>从而提高渲染性能。</p>
<p>所以，<strong>指定key时，不能通过索引index来指定</strong>。</p>
<h2 id="不推荐与v-if一起使用"><a href="#不推荐与v-if一起使用" class="headerlink" title="不推荐与v-if一起使用"></a>不推荐与v-if一起使用</h2><p><code>v-if</code>的优先级比<code>v-for</code>高，所以我们在同时使用两者时，应该通过 <strong>父子</strong> 关系来联</p>
<p>错误的示例：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div v-for=&quot;item in items&quot; <br>  v-if=&quot;item.id == 2&quot;<br>  &gt;<br>    &#123;&#123;item&#125;&#125;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br></code></pre></td></tr></table></figure>

<p>正确的示例：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;template v-for=&quot;item in items&quot; &gt;<br>    &lt;div <br>    v-if=&quot;item.id == 2&quot;<br>    &gt;<br>      &#123;&#123;item&#125;&#125;<br>    &lt;/div&gt;<br>  &lt;/template&gt;<br>&lt;/template&gt;<br></code></pre></td></tr></table></figure>

<h1 id="v-model"><a href="#v-model" class="headerlink" title="v-model"></a>v-model</h1><p>在表单输入元素或组件上创建双向绑定。</p>
<p>根据表单输入元素或组件输出的值而变化</p>
<p>最常见的就是出现在 <code>input</code> 身上</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;input type=&quot;text&quot; v-model=&quot;textValue&quot;&gt;<br>  &#123;&#123;textValue&#125;&#125;<br>&lt;/template&gt;<br><br>&lt;script setup&gt;<br>  import &#123;ref&#125; from &#x27;vue&#x27;<br><br>  const textValue = ref(&quot;&quot;)<br><br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<p><strong>修饰符</strong></p>
<p>.lazy —— 失去焦点或按下回车时更新绑定的组件属性<br>.number ——将输入的合法符串转为数字<br>.trim ——移除输入内容两端空格</p>
<h1 id="v-slot"><a href="#v-slot" class="headerlink" title="v-slot"></a>v-slot</h1><p>Vue核心之一：<strong>插槽</strong></p>
<p>具体内容我们放在后续进行讲解。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/my-blog/categories/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/" class="category-chain-item">测试开发</a>
  
  
    <span>></span>
    
  <a href="/my-blog/categories/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/Vue/" class="category-chain-item">Vue</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/my-blog/tags/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/">#测试开发</a>
      
        <a href="/my-blog/tags/%E6%B5%8B%E8%AF%95%E5%B9%B3%E5%8F%B0/">#测试平台</a>
      
        <a href="/my-blog/tags/javascript/">#javascript</a>
      
        <a href="/my-blog/tags/Vue/">#Vue</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Vue指令</div>
      <div>https://walker_kwu.gitee.io/my-blog/2022/11/07/notes/vue/directives/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>木舟</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年11月7日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年5月23日</div>
        </div>
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="NC - 非商业性使用">
                <i class="iconfont icon-nc"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="SA - 相同方式共享">
                <i class="iconfont icon-sa"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/my-blog/2022/11/07/notes/vue/reactive/" title="响应式声明">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">响应式声明</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/my-blog/2022/11/06/notes/vue/templateSyntax/" title="Vue模板语法">
                        <span class="hidden-mobile">Vue模板语法</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <span>By 木舟</span> <i class="iconfont icon-love"></i> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/my-blog/js/events.js" ></script>
<script  src="/my-blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/my-blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/my-blog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/my-blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
